FROM maven:3-jdk-8-alpine
WORKDIR /app
COPY pom.xml ./pom.xml
COPY demo-gitee-api/pom.xml ./demo-gitee-api/pom.xml
COPY gitee-api/pom.xml ./gitee-api/pom.xml
COPY spring-boot-starter-gitee/pom.xml ./spring-boot-starter-gitee/pom.xml
RUN mkdir -p /root/.m2 && echo " \
<settings xmlns=\"http://maven.apache.org/SETTINGS/1.0.0\" \
  xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \
  xsi:schemaLocation=\"http://maven.apache.org/SETTINGS/1.0.0 \
                      https://maven.apache.org/xsd/settings-1.0.0.xsd\"> \
  <mirrors> \
     <mirror> \
          <id>local</id> \
          <name>central</name> \
          <url>http://host.docker.internal:8081/repository/maven-public/</url> \
          <mirrorOf>*</mirrorOf> \
      </mirror> \
  </mirrors> \
</settings> \
" > /root/.m2/settings.xml
RUN cat /root/.m2/settings.xml
RUN mvn package -Dmaven.test.skip=true

FROM maven:3-jdk-8-alpine
WORKDIR /app
COPY --from=0 /root/.m2 /root/.m2
COPY . .
RUN mvn package -Dmaven.test.skip=true

FROM openjdk:8-jre-alpine
WORKDIR /app
ENV TZ=Asia/Shanghai
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \
    && apk add tzdata \
    && ln -snf /usr/share/zoneinfo/$TZ /etc/localtime \
    && echo $TZ > /etc/timezone

COPY --from=1 /app/demo-gitee-api/target/app.jar ./app.jar

ENTRYPOINT ["java","-jar","/app/app.jar"]
